package com.qian.service.ddj.serviceImpl;

import com.qian.api.ddj.model.OrderStatus;
import com.qian.api.ddj.service.IOrderStatusService;
import com.qian.service.ddj.dao.OrderStatusRepository;
import com.qian.service.ddj.entity.DdjOrderStatus;
import com.yaowk.service.common.BaseRepository;
import com.yaowk.service.common.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class IOrderStatusServiceImpl extends BaseServiceImpl<OrderStatus,DdjOrderStatus,Integer> implements IOrderStatusService {
    @Autowired
    private OrderStatusRepository dao;
    @Override
    public OrderStatus save(OrderStatus orderStatus){
        if (orderStatus.isNew()){
           orderStatus= entity2model(dao.save(model2Entity(orderStatus)));
        }else{
            DdjOrderStatus ddjOrderStatus = dao.findOne(orderStatus.getId());
            if (isNotEmpty(orderStatus.getAmount())){
                ddjOrderStatus.setAmount(orderStatus.getAmount());
            }
            if (isNotEmpty(orderStatus.getBussinesId())){
                ddjOrderStatus.setBussinesId(orderStatus.getBussinesId());
            }
            if (isNotEmpty(orderStatus.getCreatDate())){
                ddjOrderStatus.setCreatDate(orderStatus.getCreatDate());
            }
            if (isNotEmpty(orderStatus.getRemark())){
                ddjOrderStatus.setRemark(orderStatus.getRemark());
            }
            if (isNotEmpty(orderStatus.getStatus())){
                ddjOrderStatus.setStatus(orderStatus.getStatus());
            }
            orderStatus = entity2model(dao.save(ddjOrderStatus));
        }
        return orderStatus;
    }
    @Override
    protected BaseRepository getDao() {
        return dao;
    }

    @Override
    protected DdjOrderStatus model2Entity(OrderStatus model) {
        DdjOrderStatus ddjOrderStatus = null;
        if (isNotEmpty(model)){
            ddjOrderStatus = new DdjOrderStatus();
            ddjOrderStatus.setAmount(model.getAmount());
            ddjOrderStatus.setBussinesId(model.getBussinesId());
            ddjOrderStatus.setCreatDate(model.getCreatDate());
            ddjOrderStatus.setRemark(model.getRemark());
            ddjOrderStatus.setStatus(model.getStatus());
        }
        return ddjOrderStatus;
    }

    @Override
    protected OrderStatus entity2model(DdjOrderStatus entity) {
        OrderStatus orderStatus= null;
        if (isNotEmpty(entity)){
            orderStatus = new OrderStatus();
            orderStatus.setAmount(entity.getAmount());
            orderStatus.setBussinesId(entity.getBussinesId());
            orderStatus.setCreatDate(entity.getCreatDate());
            orderStatus.setRemark(entity.getRemark());
            orderStatus.setStatus(entity.getStatus());
        }
        return orderStatus;
    }
}
